package org.pgis.gui;

import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;

import org.pgis.core.AbstractScenePanel;

import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ColorPanel extends JPanel{

	private static final long serialVersionUID = 1L;
	private AbstractScenePanel asp;
	public ColorPanel(AbstractScenePanel asp) {
		this.asp = asp;
		initialize();
	}

	private void initialize() {
		
		this.setLayout(null);
		
		JLabel labelColor = new JLabel("Color");
		labelColor.setFont(new Font("Century", Font.BOLD, 16));
		labelColor.setBounds(87, 11, 81, 30);
		this.add(labelColor);
		
		JButton buttonObjectColor = new JButton("Object");
		buttonObjectColor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				Color bgColor = JColorChooser.showDialog(null,
                        "Choose Background Color",
                        getBackground());
				if(bgColor != null) {
					asp.getSim().setColor(bgColor);
					asp.refresh();
				}
			}
		});
		buttonObjectColor.setBounds(10, 55, 106, 32);
		this.add(buttonObjectColor);
		
		JLabel labelBackgroundColor = new JLabel();
		labelBackgroundColor.setBackground(Color.WHITE);
		labelBackgroundColor.setBounds(126, 98, 40, 30);
		this.add(labelBackgroundColor);
		
		JButton buttonBackgroundColor = new JButton("Background");
		buttonBackgroundColor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Color bgColor = JColorChooser.showDialog(null,
			                                 "Choose Background Color",
			                                 getBackground());
				if(bgColor != null) {
					asp.setBackgroundColor(bgColor);
				}
			}
		});
		buttonBackgroundColor.setBounds(10, 98, 106, 32);
		this.add(buttonBackgroundColor);
		
		JLabel labelObjectColor = new JLabel("");
		labelObjectColor.setBackground(Color.BLACK);
		labelObjectColor.setBounds(126, 57, 40, 30);
		this.add(labelObjectColor);
	}
}
